var checkInterval;
var intervalCount;
$(document).ready(function() {
    jQuery.validator.setDefaults({
        debug: true,
        success: "valid"
    });
    $('#form-pass').validate({
        rules: {
            "password": {
                required: true
            },
            "password_new": {
                required: true,
                minlength: 5
            },
            "password_new2": {
                required: true,
                minlength: 5,
                equalTo: "#password_new"
            }
        }
    });
});

function cambiarPassClick() {
    if (!$('#form-pass').valid())
        return;
    $.ajax({
        url: '/academico/changepass/changepassword',
        type: 'post',
        dataType: 'json',
        data: {
            'old_pass': $('#password').val(),
            'new_pass': $('#password_new').val()
        },
        success: function(data) {
            if (data.response === "success") {
                $('#password').val('');
                $('#password_new').val('');
                $('#password_new2').val('');
                $('#div-alert').html('<div class="alert alert-success alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>Contrase&ntilde;a actualizada correctamente</div>');
            } else {
                $('#div-alert').html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button><strong>Error! </strong>' + data.message + '</div>');
            }
            setInterval(function() {
                $('#div-alert').html("");
            }, 3000);
        }
    });
}